<template>
  <!-- Excel 导入功能组件 -->
  <upload-excel :on-success="handleSuccess" />
</template>

<script>
import { importEmployeeAPI } from '@/api'
import { formatExcelDate } from '@/utils'
export default {
  name: 'Excel',
  methods: {
    // 导入成功以后的回调函数
    async handleSuccess({ results, header }) {
      // console.log(results)
      // console.log(header)
      const obj = {
        入职日期: 'timeOfEntry',
        转正日期: 'correctionTime',
        手机号: 'mobile',
        姓名: 'username',
        工号: 'workNumber'
      }
      const newArry = results.map((item) => {
        const newObj = {}
        for (const key in item) {
          // console.log(key)
          const enkey = obj[key]
          if (enkey === 'correctionTime' || enkey === 'timeOfEntry') {
            // 时间需要处理
            const value = formatExcelDate(item[key])
            newObj[enkey] = value
          } else {
            newObj[enkey] = item[key]
          }
        }
        return newObj
      })
      // console.log(newArry)

      // 处理完数据准备发送请求
      //   const res =
      await importEmployeeAPI(newArry).catch((err) => err)
    //   console.log(res)
    }
  }
}
</script>

<style lang="scss" scoped></style>

